home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261sr4.zip / GS_INIT.PS < prev    next >
Text File  |  1993-05-28  |  29KB  |  902 lines

  1. %    Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2. %
  3. % This file is part of Ghostscript.
  4. %
  5. % Ghostscript is distributed in the hope that it will be useful, but
  6. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. % to anyone for the consequences of using it or for whether it serves any
  8. % particular purpose or works at all, unless he says so in writing.  Refer
  9. % to the Ghostscript General Public License for full details.
  10. %
  11. % Everyone is granted permission to copy, modify and redistribute
  12. % Ghostscript, but only under the conditions described in the Ghostscript
  13. % General Public License.  A copy of this license is supposed to have been
  14. % given to you along with Ghostscript so you can know your rights and
  15. % responsibilities.  It should be in a file named COPYING.  Among other
  16. % things, the copyright notice and this notice must be preserved on all
  17. % copies.
  18.  
  19. % Initialization file for the interpreter.
  20. % When this is run, systemdict is still writable.
  21.  
  22. % Comment lines of the form
  23. %    %% Replace <n> <file(s)>
  24. % indicate places where the next <n> lines should be replaced by
  25. % the contents of <file(s)>, when creating a single merged init file.
  26.  
  27. % Check the interpreter revision.  NOTE: the interpreter code requires
  28. % that the first non-comment token in this file be an integer.
  29. 261
  30. dup revision ne
  31.  { (gs: Interpreter revision \() print revision 10 string cvs print
  32.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  33.    (\).\n) print flush 1 .quit
  34.  }
  35. if pop
  36.  
  37. % Define true and false.
  38. systemdict begin
  39. /true 0 0 eq def
  40. /false 0 1 eq def
  41. end
  42.  
  43. % Acquire userdict.
  44. currentdict dup 200 .setmaxlength        % userdict
  45. systemdict begin
  46. /userdict exch def
  47.  
  48. % Acquire the debugging flags.
  49. currentdict /DEBUG known   /DEBUG exch def
  50.   /VMDEBUG
  51.     DEBUG {{print ( ) print vmstatus pop (      ) cvs print pop ( ) print
  52.             systemdict length (      ) cvs print (\n) print flush}}
  53.       {{pop}} ifelse
  54.   def
  55. currentdict /DISKFONTS known   /DISKFONTS exch def
  56. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  57. currentdict /NOBIND known   /NOBIND exch def
  58. /.bind /bind load def
  59. NOBIND { /bind { } def } if
  60. currentdict /NOCACHE known   /NOCACHE exch def
  61. currentdict /NODISPLAY known   not /DISPLAYING exch def
  62. currentdict /NOPAUSE known   /NOPAUSE exch def
  63. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  64. currentdict /OUTPUTFILE known    % obsolete
  65.  { /OutputFile /OUTPUTFILE load def
  66.    currentdict /OUTPUTFILE undef
  67.  } if
  68. currentdict /QUIET known   /QUIET exch def
  69. currentdict /SAFER known   /SAFER exch def
  70. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  71.  
  72. % Acquire environment variables.
  73. currentdict /DEVICE known not
  74.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  75.  
  76. QUIET not { (Initializing... ) print flush } if
  77.  
  78. (START) VMDEBUG
  79.  
  80. % Acquire the standard files.
  81. /.stdin (%stdin) (r) file def
  82. /.stdout (%stdout) (w) file def
  83. /.stderr (%stderr) (w) file def
  84.  
  85. % Turn on array packing for the rest of initialization.
  86. true setpacking
  87.  
  88. % Define a procedure for skipping over an unneeded section of code.
  89. % This avoids allocating space for the skipped procedures.
  90. /.skipeof    % string ->
  91.  { { dup currentfile =string readline pop eq { exit } if } loop pop
  92.  } bind def
  93.  
  94. % Define a special version of def for making operator procedures.
  95. /odef
  96.     {1 index exch .makeoperator def} bind def
  97.  
  98. % Define predefined procedures substituting for operators,
  99. % in alphabetical order.
  100.  
  101. userdict /#copies 1 put
  102. /[    /mark load def
  103. /]     {counttomark array astore exch pop} odef
  104. /abs    {dup 0 lt {neg} if} odef
  105. /copypage
  106.     { 1 false .outputpage
  107.       (>>copypage, press <return> to continue<<\n) .confirm
  108.     } odef
  109. /defaultmatrix
  110.     {currentdevice exch deviceinitialmatrix} odef
  111. /.echo /echo load def
  112. userdict /.echo.mode true put
  113. /echo    {dup /.echo.mode exch store .echo} odef
  114. /eexec
  115.     { 55665 .filter_eexecDecode
  116.       cvx systemdict begin stopped
  117.       % Only pop systemdict if it is still the top element,
  118.       % because this is apparently what Adobe interpreters do.
  119.       currentdict systemdict eq { end } if
  120.       { stop } if
  121.     } bind def
  122. /executive
  123.     { { prompt
  124.         { (%statementedit) (r) file } stopped { exit } if
  125.         cvx execute
  126.       } loop
  127.     } odef
  128. /framedevice
  129.     {.stderr (Warning: framedevice is an obsolete operator.\n) writestring
  130.      .stderr flushfile
  131.      pop pop pop setmatrix initclip} odef
  132. /handleerror
  133.     {errordict /handleerror get exec} bind def
  134. /identmatrix
  135.     {{1.0 0.0 0.0 1.0 0.0 0.0} cvlit exch copy} odef
  136. /initgraphics
  137.     {initmatrix newpath initclip 1 setlinewidth 0 setlinecap 0 setlinejoin
  138.      [] 0 setdash 0 setgray 10 setmiterlimit} odef
  139. /initmatrix
  140.     {.tempmatrix defaultmatrix setmatrix} odef
  141. /languagelevel 1 def        % we don't have full Level 2
  142. /matrix    {6 array identmatrix} odef
  143. /prompt    {flush flushpage
  144.      (GS) print count 0 ne
  145.       {(<) print count =only}
  146.      if (>) print flush} bind def
  147. /pstack    {0 1 count 3 sub {index ==} for} def
  148. /quit    {0 .quit} odef
  149. /run    {dup type /filetype eq
  150.       { true }
  151.       { findlibfile { exch pop true } { false } ifelse }
  152.      ifelse
  153.       {cvx execute}
  154.       {(r) file}        % let the error happen
  155.      ifelse} odef
  156. /showpage
  157.     { #copies true .outputpage
  158.       (>>showpage, press <return> to continue<<\n) .confirm
  159.       erasepage initgraphics
  160.     } odef
  161. % Code output by Adobe Illustrator relies on the fact that
  162. % `stack' is a procedure, not an operator!!!
  163. /stack    {0 1 count 3 sub {index =} for} bind def
  164. /start    { executive } def
  165. % This interpreter is compatible with PostScript "version" 54.0 (I think).
  166. /version (54.0) def
  167.  
  168. % Provide semi-fake but usable definitions for some of
  169. % the color PostScript extensions.
  170. /setcolorscreen {
  171.     setscreen 9 {pop} repeat
  172. } odef
  173. /currentcolorscreen {
  174.     currentscreen 3 copy 6 copy
  175. } odef
  176.  
  177. % Define some additional built-in procedures (beyond the ones defined by
  178. % the PostScript Language Reference Manual).
  179. % Warning: these are not guaranteed to stay the same from one Ghostscript
  180. % release to the next!
  181.  
  182. /concatstrings
  183.     { exch dup length 2 index length add string    % str2 str1 new
  184.       dup dup 4 2 roll copy        % str2 new new new1
  185.       length 4 -1 roll putinterval
  186.     } bind def
  187. /copyarray
  188.     { dup length array copy } bind def
  189. /copystring
  190.     { dup length string copy } bind def
  191. /.dicttomark        % (the Level 2 >> operator)
  192.     { counttomark 2 idiv dup dict begin
  193.        { def } repeat pop currentdict end
  194.     } bind def
  195. /finddevice
  196.     { systemdict /devicedict get exch get } bind def
  197. /.growdict        % grow a dictionary
  198.     { dup length 3 mul 2 idiv 1 add .setmaxlength
  199.     } bind def
  200. /.growput        % put, grow the dictionary if needed
  201.     { 2 index length 3 index maxlength eq
  202.        { 3 copy pop known not { 2 index .growdict } if
  203.        } if
  204.       put
  205.     } bind def
  206. /selectdevice
  207.     { finddevice setdevice } bind def
  208. /signalerror        % object errorname
  209.     { errordict exch get exec } bind def
  210.  
  211. % Define =string, which is used by some PostScript programs even though
  212. % it isn't documented anywhere.
  213. /=string 128 string def
  214.  
  215. % Define the =[only] procedures.  Also define =print,
  216. % which is used by some PostScript programs even though
  217. % it isn't documented anywhere.
  218. /=    { =only (\n) print } bind def
  219. /=only    { { =string cvs } stopped { pop pop (--nostringval--) } if print } bind def
  220. /=print    /=only load def
  221. % Temporarily define == as = for the sake of run0.
  222. /== /= load def
  223.  
  224. % Define the filter operator.
  225.  
  226. /.filterstring (.filter_01234567890123456789) def
  227. /.filterstring1 .filterstring 8 .filterstring length 8 sub getinterval def
  228. /filter
  229.     { //.filterstring exch 0 exch
  230.       //.filterstring1 cvs length 8 add getinterval cvn load exec
  231.     } odef
  232. systemdict /.filter_LZWEncode undef    % per FSF
  233.  
  234. % Define procedures for getting and setting the current device resolution.
  235.  
  236. /gsgetdeviceprop
  237.  { 1 index getdeviceprops
  238.     { 1 index counttomark 1 add index eq { exit } if pop pop } loop
  239.    dup mark eq        % if true, not found
  240.     { pop dup /undefined signalerror }
  241.     { counttomark 1 add 1 roll cleartomark exch pop exch pop }
  242.    ifelse
  243.  } bind def
  244. /gscurrentresolution
  245.  { currentdevice /HWResolution gsgetdeviceprop
  246.  } bind d